package br.com.simora.crawler;

import javax.inject.Named;

import org.apache.log4j.Logger;

import br.com.simora.musica.Artista;
import br.com.simora.musica.Musica;
import br.com.simora.radio.RadioEnum;

@Named("itapemarsfm")
public class ItapemaRSFMCrawler extends AbstractCrawler {
	private static Logger logger = Logger.getLogger(ItapemaRSFMCrawler.class);
	private static String URL = "http://itapema.clicrbs.com.br/service.php?url=schedule%2Flive%2Fitapema%2FRS";
	
	@Override
	public void recuperaInfo(){
		recuperador.setUrl(URL, "html");
		String itensConteudo = recuperador.getPagina().getConteudo();
		String artistaNome = "";
		String musicaNome = "";
		if(!"".equals(itensConteudo) && null != itensConteudo){
			itensConteudo = itensConteudo.replace("\"", "").replace("}", "").replace("{", "");
			String[] itens = itensConteudo.split(",");
			for(int i=0; i < itens.length; i++){
				if(itens[i].contains(":")){
					String[] itemFim = itens[i].split(":");
					if("performer".equals(itemFim[0])){
						artistaNome = itemFim[1];
					}
					if("music".equals(itemFim[0])){
						musicaNome = itemFim[1];
					}
					if(!"".equals(artistaNome) && !"".equals(musicaNome)){
						artista = new Artista();
						artista.setNome(artistaNome.trim());
						musica = new Musica();
						musica.setNome(musicaNome.trim());
						break;
					}
				}
			}
		}
		logger.debug(artistaNome + " - " + musicaNome);
	}

	@Override
	public void setRadioNome() {
		this.radioNome = RadioEnum.itapemarsfm.getNome();
	}

}